import { onMounted, provide, ref } from 'vue'
import { getShiftTime } from '/src/api/platform/mes/screen'

export default function () {
  const shiftCode = ref('--')
  const shiftDate = ref('--')
  const shiftDateTime = ref('--')

  provide('shiftCode', shiftCode)
  provide('shiftDate', shiftDate)
  const shiftTime = () => {
    getShiftTime().then(res => {
      shiftCode.value = res.shiftCode
      shiftDate.value = res.dateStr && res.dateStr.length > 9 ? res.dateStr.slice(0, 10) : '--'
      shiftDateTime.value = res.dateStr
    })
  }
  onMounted(() => {
    shiftTime()
    setInterval(shiftTime, 3000)
  })
  return { shiftCode, shiftDate }
}
